an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text
jupyter stands for julia, python, and r
jupyter notebook is included in the anaconda distribution - see notes on conda
however, here are some options if you need to install it manaully:
python3 -m pip install jupyter
python -m pip install jupyter
pip3 install jupyter
pip install jupyter
conda install jupyterThe ipython kernel is the python execution backend for jupyter
# list all kernels
jupyter kernelspec list
# add a kernel using an existing conda environment
myenv=how2-py
conda activate $myenv
pip install -U ipykernel
python -m ipykernel install --user --name $myenv --display-name $myenv
jupyter kernelspec list
# delete a kernel
jupyter kernelspec uninstall unwanted-kernelSee which python you are using - i.e. the python associated with the kernel
import sys
print(sys.executable)
print(sys.version)See which python jupyter notebook was launched from - this is not necessarily the same as the python associated with the kernel (unless the environment you launched from is also the environment associated with the kernel)
# python 3
import subprocess
print(subprocess.getoutput("which python"))# python 2
import commands
print(commands.getoutput("which python"))Things I’ve noticed:
I’ve added two kernels - py2 and py3
if I launch jupyter from py2 then the available kernels are py2, py3 and Python 2, where Python 2 is identical to py2
if I launch jupyter from py3 then the available kernels are py2, py3 and Python 3, where Python 3 is identical to py3
if I launch jupyter from base then the available kernels are py2, py3 and Python 3, where Python 3 is identical to base
so I think that whichever python environment you launch from gets assigned to a default kernel - either Python 2 or Python 3 - which exists is in addition to any kernels you have added manually.
TODO
# install the R essentials in your current environment
conda install -c r r-essentialsTODO
# see which magic commands are available in your interpreter
%lsmagicexamples:
| command | description |
|---|---|
%quickref |
show a quick reference sheet for IPython |
%matplotlib inline |
|
%save |
|
%clear |
|
%debug |
|
%time |
|
%timeit |
|
%pdb |
debug |
%prun |
performance run |
%writefile |
saves contents of a cell to an external file |
%pycat |
shows syntax highlighted contents of an external file |
%who |
list variables of global scope |
%store |
pass variables between notebooks |
%load |
insert code from external script |
%run |
execute python code |
%env |
set environment variables |
%% for multiline expressions? before the command (or function) to get helppip install ipython-sql
pip install cython
pip install rpy2%load_ext sql # pip install ipython-sql
%load_ext cython
%load_ext rpy2.ipython! before the command!ls
!cd
!pwd| shortcut | action |
|---|---|
| shift + enter | run cell, select below |
wrap latex code (e.g. equations) between double dollar signs $$
to run the official Jupyter Notebook image:
docker run --rm -it -p 8888:8888 -v "$(pwd):/notebooks" jupyter/notebook other images are available, e.g.
jupyter/datascience-notebook